package models;

import java.io.Serializable;
import javax.persistence.*;

import java.util.Date;

/**
 * The persistent class for the loan_app database table.
 * 
 */
@Entity
@Table(name = "LOAN_APP")
public class LoanApp implements Serializable {
    private static final long serialVersionUID = 1L;

    @Id
    @TableGenerator(
            name = "LOAN_APP_SEQ",
            table = "SEQUENCE",
            pkColumnName = "NAME",
            pkColumnValue = "LOAN_APP_SEQ",
            valueColumnName = "CNT",
            initialValue = 10000,
            allocationSize = 1)
    @GeneratedValue(strategy = GenerationType.TABLE, generator = "LOAN_APP_SEQ")
    @Column(unique = true, nullable = false)
    private Integer id;

    private Integer aid;

    private double amount;

    @Column(name = "Loan_Id")
    private Integer loanId;

    @Temporal(TemporalType.TIMESTAMP)
    @Column(name = "APP_D")
    private Date appD;

    @Temporal(TemporalType.TIMESTAMP)
    @Column(name = "APP_EXPIRE_D")
    private Date appExpireD;

    @Temporal(TemporalType.TIMESTAMP)
    @Column(name = "CREATE_D")
    private Date createD;

    @Column(length = 500)
    private String description;

    private int duration;

    @Column(name = "LOAN_TYPE")
    private int loanType;

    @Column(length = 200)
    private String name;

    @Column(name = "PAYMENT_MODE")
    private int paymentMode;

    @Column(name = "PROG_ID")
    private Integer progId;

    private int purpose;

    private int status;

    @Temporal(TemporalType.TIMESTAMP)
    @Column(name = "STATUS_D")
    private Date statusD;

    @Temporal(TemporalType.TIMESTAMP)
    @Column(name = "UPDATE_D")
    private Date updateD;

    public LoanApp() {
    }

    public void setValues(LoanPurpose purpose, LoanType loanType, double amount, int duration,
            PaymentMethod paymentMethod) {
        this.setPurpose(purpose.ordinal());
        this.setLoanType(loanType);
        this.setAmount(amount);
        this.setDuration(duration);
        this.setPaymentMode(paymentMethod);
    }

    public static enum Status {
        ANY("Internal", "Internal"), // 0 -- internal for use by admin app only
        NONE("Pending", "Pending"), // 1 -- no status yet set
        AUTH_FAIL("Failed Authentication", "Canceled"), // 2 -- Knowledge based
        RULES_FAIL("Failed CREDIT Rules", "Canceled"), // 3 -- rejected by rules
        AUTH_PASS("Passed Authentication", "Submitted"), // 4 -- Knowledge based
        RULES_PASS("Passed CREDIT Rules", "Offered"), // 5 -- Passed rules
        SUBMITTED("Submitted", "Listed"), // 6 -- loan application submited
        DUPLICATE("Duplicate", "Duplicate"), // 7 -- identified as duplicate
        ERROR("Error", "Error"), // 8 -- error in processing
        APPROVED_CR("Approved", "Listed"), // 9 -- application is approved by
        REJECTED_CR("Rejected", "Canceled"), // 10 -- application is rejected by
        INREVIEW_CR("In Review", "Listed"), // 11 -- application is being
        ;

        private String m_label = null;

        private String m_partnerLabel = null;

        private Status(String statusString, String partnerLabel) {
            m_label = statusString;
            m_partnerLabel = partnerLabel;
        }

        public String getLabel() {
            return this.m_label;
        }

        public String getPartnerLabel() {
            return this.m_partnerLabel;
        }
    }

    public static enum LoanType {
        PERSONAL("个人贷款"), // 0
        BUSINESS("商业贷款"), // 1
        ANY("any")// 2
        ;
        private String label;

        LoanType(String label) {
            this.label = label;
        }

        public String getLabel() {
            return this.label;
        }

        public static LoanType getLoanTypeByLabel(String label) {
            for (LoanType item : LoanType.values()) {
                if (item.getLabel().equals(label)) {
                    return item;
                }
            }
            return null;
        }

        public static LoanType getLoanTypeByName(String name) {
            for (LoanType item : LoanType.values()) {
                if (item.name().equals(name)) {
                    return item;
                }
            }
            return null;
        }
    }

    public static enum LoanPurpose {
        SHOPPING("个人购物"), // 0
        ;
        private String label;

        LoanPurpose(String label) {
            this.label = label;
        }

        public String getLabel() {
            return this.label;
        }

        public static LoanPurpose getLoanPurposeByLabel(String label) {
            for (LoanPurpose item : LoanPurpose.values()) {
                if (item.getLabel().equals(label)) {
                    return item;
                }
            }
            return null;
        }

        public static LoanPurpose getLoanPurposeByName(String name) {
            for (LoanPurpose item : LoanPurpose.values()) {
                if (item.name().equals(name)) {
                    return item;
                }
            }
            return null;
        }
    }

    public static enum PaymentMethod {
        AMORTIZATION(0), // 0
        SESSION(3), // 1
        HALF_YEAR(6), // 2
        PAY_AT_THE_END(-1), // 3
        ;
        private int _paymentFrequency;

        PaymentMethod(int paymentFrequency) {
            this._paymentFrequency = paymentFrequency;
        }

        public int getPaymentFrequency() {
            return this._paymentFrequency;
        }
    }

    public Integer getId() {
        return this.id;
    }

    public void setId(Integer id) {
        this.id = id;
    }

    public Integer getAid() {
        return this.aid;
    }

    public void setAid(Integer aid) {
        this.aid = aid;
    }

    public double getAmount() {
        return this.amount;
    }

    public void setAmount(double amount) {
        this.amount = amount;
    }

    public Date getAppD() {
        return this.appD;
    }

    public void setAppD(Date appD) {
        this.appD = appD;
    }

    public Date getAppExpireD() {
        return this.appExpireD;
    }

    public void setAppExpireD(Date appExpireD) {
        this.appExpireD = appExpireD;
    }

    public Date getCreateD() {
        return this.createD;
    }

    public void setCreateD(Date createD) {
        this.createD = createD;
    }

    public String getDescription() {
        return this.description;
    }

    public void setDescription(String description) {
        this.description = description;
    }

    public int getDuration() {
        return this.duration;
    }

    public void setDuration(int duration) {
        this.duration = duration;
    }

    public LoanType getLoanType() {
        return LoanType.values()[this.loanType];
    }

    public void setLoanType(LoanType loanType) {
        this.loanType = loanType.ordinal();
    }

    public String getName() {
        return this.name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public PaymentMethod getPaymentMode() {
        return PaymentMethod.values()[this.paymentMode];
    }

    public void setPaymentMode(PaymentMethod paymentMode) {
        this.paymentMode = paymentMode.ordinal();
    }

    public Integer getProgId() {
        return this.progId;
    }

    public void setProgId(Integer progId) {
        this.progId = progId;
    }

    public int getPurpose() {
        return this.purpose;
    }

    public void setPurpose(int purpose) {
        this.purpose = purpose;
    }

    public Status getStatus() {
        return Status.values()[this.status];
    }

    public void setStatus(Status status) {
        this.status = status.ordinal();
    }

    public Date getStatusD() {
        return this.statusD;
    }

    public void setStatusD(Date statusD) {
        this.statusD = statusD;
    }

    public Date getUpdateD() {
        return this.updateD;
    }

    public void setUpdateD(Date updateD) {
        this.updateD = updateD;
    }

    public Integer getLoanId() {
        return loanId;
    }

    public void setLoanId(Integer loanId) {
        this.loanId = loanId;
    }

}
